#![feature(proc_macro_hygiene, decl_macro)]

#[macro_use] extern crate rocket;
#[macro_use] extern crate serde_derive;

use rocket_contrib::json::{Json};
use std::sync::Mutex;
use std::collections::HashMap;

/** 实体 **/
#[derive(Serialize, Deserialize)]
struct User {
    name: String,
    account: usize,
}



use rocket::http::RawStr;
use rocket_contrib::serve::StaticFiles;

#[get("/")]
fn index() -> &'static str {
    "Hello, world!"
}

#[get("/hello?wave&<name>")]
fn hello(name: &RawStr) -> String {
    format!("Hello, {}!", name.as_str())
}


#[get("/user/<id>", format = "json")]
fn user(id: usize) -> Json<User> { 
    Json(User {
        name: String::from("jaakan"),
        account: id
    })
 }


fn main() {
    rocket::ignite() //
    .mount("/", routes![index,hello]) // 
    .mount("/", routes![user]) // 返回JSON类型 发起的请求需要是 Content-Type = application/json;charset=UTF-8   否则会报404
    .mount("/public", StaticFiles::from("static")) // 静态资源 文件夹放在项目下即可,无需放在src中
    .launch();
}
